package com.gxan.service.impl;

import com.gxan.common.LayuiRepResult;
import com.gxan.dao.SalaryManagementDao;
import com.gxan.dao.impl.SalaryManagementDaoimpl;
import com.gxan.entity.Dep;
import com.gxan.entity.DepS;
import com.gxan.entity.PayList;
import com.gxan.entity.Register;
import com.gxan.service.SalaryManagementService;

import java.sql.SQLException;
import java.util.List;

public class SalaryManagementServiceimpl implements SalaryManagementService {

    SalaryManagementDao salaryManagement = new SalaryManagementDaoimpl();

    @Override
    public LayuiRepResult findAll(Integer page,Integer limit){
        try{

            Integer offset = (page - 1) * limit;

            Integer rows = limit;
            //查询数据
            List<PayList> paylist = salaryManagement.findAll(offset,rows);
            //统计总条数
            Integer countPayList = salaryManagement.countPayList();
            //返回结果
            return LayuiRepResult.success(countPayList,paylist);

        } catch (Exception e){
            e.printStackTrace();
            return LayuiRepResult.error();
        }



    }
    @Override
    public LayuiRepResult addRoll(Dep dep){



        try {

            Integer result = salaryManagement.addRoll(dep);

            if (result > 1 ) {
                return LayuiRepResult.success("添加成功","0");
            }

        } catch (SQLException e) {

            return LayuiRepResult.error("添加成功");

        }


        return null;


    }

    public LayuiRepResult delRoll(String id){

        try {

            Integer result = salaryManagement.delRoll(id);
            if (result > 0) {
                return LayuiRepResult.success("删除成功", 0);
            }



        } catch (SQLException e) {

            return LayuiRepResult.error();

        }


        return null;
    }
    public LayuiRepResult editRoll(PayList payList){

        try {

            if(salaryManagement.editRoll(payList) > 0){

                return LayuiRepResult.success("修改成功",0);

            }

        } catch (SQLException e) {

            return LayuiRepResult.error();

        }

        return null;
    }

    public LayuiRepResult batchdelRoll(String[] ids){

        try {
            if(salaryManagement.batchdelRoll(ids) > 0){

                return LayuiRepResult.success("删除",0);

            }
        } catch (SQLException ex) {
            return LayuiRepResult.error();
        }



        return null;
    }

    public LayuiRepResult findDepartment(){

        try {

            List deps = salaryManagement.findDepartment();



            return LayuiRepResult.success(deps);

        } catch (SQLException e) {
            return LayuiRepResult.error();
        }


    }

    public LayuiRepResult findAllDeps(Integer page,Integer limit){

        try {
            Integer offset = (page - 1) * limit;

            Integer rows = limit;

            List<DepS> depS = salaryManagement.findAllDeps(offset,rows);


            Integer countDepsList = salaryManagement.countDepsList();
            //返回结果
            return LayuiRepResult.success(countDepsList,depS);

        } catch (SQLException e) {
           return LayuiRepResult.error();
        }


    }

    public LayuiRepResult search(String depsName){

        try {

            List<DepS> depS = salaryManagement.search(depsName);

            return LayuiRepResult.success(depS);


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
    @Override
    public LayuiRepResult findAlregisterl(String dep){
        try{


            //查询数据
            List<Register> paylist = salaryManagement.findAlregisterl(dep);


            //返回结果
            return LayuiRepResult.success(paylist);

        } catch (Exception e){
            e.printStackTrace();
            return LayuiRepResult.error();
        }



    }

}
